package com.hzjy.manage.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.hzjy.api.beans.HzjyTradingnews;
import com.hzjy.api.service.impl.HzjyTradingnewsServiceImpl;
import com.hzjy.common.utils.PageData;
import com.hzjy.manage.service.impl.HzjyTradingNoticeServiceImpl;
import com.hzjy.api.beans.HzjyTradingNotice;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.utils.poi.ExcelUtil;
import com.hzjy.common.core.page.TableDataInfo;

/**
 * 挂牌公告Controller
 *
 * @author hzjy
 * @date 2020-09-05
 */
@RestController
@RequestMapping("/manage/notice")
public class HzjyTradingNoticeController extends BaseController {
    @Autowired
    private HzjyTradingnewsServiceImpl hzjyTradingnewsServiceImpl;

    /**
     * 查询挂牌资讯列表
     */
    @PreAuthorize("@ss.hasPermi('manage:notice:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody PageData pd) {
        Object currentPage = pd.get("currentPage");
        if (currentPage == null || Integer.parseInt(currentPage.toString()) == 0) {
            pd.put("currentPage", 0);
            currentPage = 1;
        } else {
            pd.put("currentPage", (Integer.parseInt(pd.get("currentPage").toString()) - 1) * pd.getInteger("size"));
        }
        Map map = hzjyTradingnewsServiceImpl.queryTradingNewsPage(pd);
        map.put("currentPage", currentPage); //选择的页数
        return AjaxResult.success(200, "查询成功", map);
    }

    /**
     * 导出挂牌资讯列表
     */
    /*@PreAuthorize("@ss.hasPermi('manage:notice:export')")
    @GetMapping("/export")
    public AjaxResult export(HzjyTradingNotice hzjyTradingNotice) {
        List<HzjyTradingNotice> list = hzjyTradingNoticeService.selectHzjyTradingNoticeList(hzjyTradingNotice);
        ExcelUtil<HzjyTradingNotice> util = new ExcelUtil<HzjyTradingNotice>(HzjyTradingNotice.class);
        return util.exportExcel(list, "notice");
    }*/

    /**
     * 获取挂牌公告详细信息
     */
    /*@PreAuthorize("@ss.hasPermi('manage:notice:query')")
    @GetMapping("/selectOne")
    public AjaxResult getInfo(@PathVariable("tradingNoticeId") Long tradingNoticeId) {
        return AjaxResult.success(hzjyTradingNoticeService.selectHzjyTradingNoticeById(tradingNoticeId));
    }*/

    /**
     * 新增挂牌资讯
     */
    @PreAuthorize("@ss.hasPermi('manage:notice:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody HzjyTradingnews hzjyTradingnews) {
        hzjyTradingnews.setTime(new Date());
        return toAjax(hzjyTradingnewsServiceImpl.insertHzjyTradingnews(hzjyTradingnews));
    }

    /**
     * 修改挂牌资讯
     */
    @PreAuthorize("@ss.hasPermi('manage:notice:edit')")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody HzjyTradingnews hzjyTradingnews) {
        return toAjax(hzjyTradingnewsServiceImpl.updateHzjyTradingnews(hzjyTradingnews));
    }

    /**
     * 删除挂牌资讯
     */
    @PreAuthorize("@ss.hasPermi('manage:notice:remove')")
    @DeleteMapping("/{tradingNoticeIds}")
    public AjaxResult remove(@PathVariable Long[] tradingNoticeIds) {
        return toAjax(hzjyTradingnewsServiceImpl.deleteHzjyTradingnewsByIds(tradingNoticeIds));
    }

    /**
     * 删除挂牌资讯
     */
    @PreAuthorize("@ss.hasPermi('manage:notice:remove')")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody HzjyTradingnews hzjyTradingnews) {
        return toAjax(hzjyTradingnewsServiceImpl.deleteHzjyTradingnewsById(hzjyTradingnews.getId()));
    }
}
